<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            我自己做的后台管理中心
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/php/Fly/Public/admin/css/x-admin.css" media="all">
        <script src="/php/Fly/Public/Admin/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/php/Fly/Public/admin/js/x-layui.js" charset="utf-8"></script>
    </head>
    <body>

    
        <div class="x-body">
            <form class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="L_title" class="layui-form-label">
                        标题
                    </label>
                    <div class="layui-input-block">
                        <input type="text" id="L_title" name="title" required="" lay-verify="title"
                        value="<?php echo $data['title'] ?>" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <textarea id="L_content" name="content" placeholder="请输入内容" class="layui-textarea fly-editor layui-hide"
                        style="height: 260px;">
                            <?php echo $data['content'] ?>
                        </textarea>
                        <div class="layui-layedit">
                            <div class="layui-unselect layui-layedit-tool">
                                <i class="layui-icon layedit-tool-b" title="加粗" lay-command="Bold" layedit-event="b"
                                "=" "></i><i class="layui-icon layedit-tool-i " title="斜体
                                " lay-command="italic " layedit-event="i " "="">
                                    
                                </i>
                                <i class="layui-icon layedit-tool-u" title="下划线" lay-command="underline"
                                layedit-event="u" "=" "></i><i class="layui-icon layedit-tool-d
                                " title="删除线 " lay-command="strikeThrough " layedit-event="d " "="">
                                    
                                </i>
                                <span class="layedit-tool-mid">
                                </span>
                                <i class="layui-icon layedit-tool-left" title="左对齐" lay-command="justifyLeft"
                                layedit-event="left" "=" "></i><i class="layui-icon layedit-tool-center
                                " title="居中对齐 " lay-command="justifyCenter " layedit-event="center " "="">
                                    
                                </i>
                                <i class="layui-icon layedit-tool-right" title="右对齐" lay-command="justifyRight"
                                layedit-event="right" "=" "></i><span class="layedit-tool-mid
                                "></span><i class="layui-icon layedit-tool-link " title="插入链接 " layedit-event="link " "="">
                                    
                                </i>
                                <i class="layui-icon layedit-tool-unlink layui-disabled" title="清除链接"
                                lay-command="unlink" layedit-event="unlink" "=" "></i><i class="layui-icon
                                layedit-tool-face " title="表情 " layedit-event="face " "="">
                                    
                                </i>
                                <i class="layui-icon layedit-tool-image" title="图片" layedit-event="image">
                                    
                                   
                                </i>
                            </div>
                            <div class="layui-layedit-iframe">
                                <iframe id="LAY_layedit_1" name="LAY_layedit_1" textarea="L_content" frameborder="0"
                                style="height: 280px;">
                                </iframe>
                            </div>
                        </div>
                    </div>
                    <label for="L_content" class="layui-form-label" style="top: -2px;">
                        描述
                    </label>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">
                            所在类别
                        </label>
                        <div class="layui-input-block">
                            <select lay-verify="required" name="cid">
                                <option>
                                </option>
                                <?php foreach ($cate as $row) { ?>
                                    
                               
                                <optgroup label="<?php echo $row['name'] ?>">
                                <?php foreach ($row['son'] as $cateson) { ?>

                                    <option value="<?php echo $cateson['id'] ?>"><?php echo $cateson['name'] ?></option>

                                <?php } ?>
                                </optgroup>
                                <?php  } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                 <input type="hidden" name="id" value="<?php echo $data['id'] ?>">
                    <button class="layui-btn" lay-filter="add" lay-submit="">
                        保存
                    </button>
                </div>
            </form>
        </div>
        <script>
            layui.use(['form', 'layer', 'layedit'],
            function() {
                $ = layui.jquery;
                var form = layui.form(),
                layer = layui.layer,
                layedit = layui.layedit;

                layedit.set({
                    uploadImage: {
                        url: "./upimg.json" //接口url
                        ,
                        type: 'post' //默认post
                    }
                })

                //创建一个编辑器
                editIndex = layedit.build('L_content');

                //监听提交
                form.on('submit(add)',function(data) {
                    // console.log(data);

                    content = layedit.getContent(editIndex);

                    if(content.length<10){
                        layer.msg("内容不能少于10长度");
                        return false;
                    }
                    data.field.content=content;
                    // console.log(data.field);
                    //发异步，把数据提交给php
                    $.ajax({
                        url: '<?php echo U('admin/question/question_add');?>',
                        type: 'POST',
                        dataType: 'json',
                        data: data.field,
                    })
                    .done(function(respones) {
                        if(respones.error==1){
                            // 把失败信息弹出
                            layer.msg(respones.info, function(){});
                        }else{
                            layer.alert("保存成功", {
                                icon: 6
                            },
                            function() {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                parent.location.reload();
                            
                            });
                        }
                    })
                    return false;
                });
            });
        </script>
 

    </body>
</html>